package com.qiudaozhang.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qiudaozhang.dto.ResponseCode;
import com.qiudaozhang.mapper.DataDictionaryMapper;
import com.qiudaozhang.model.DataDictionary;
import com.qiudaozhang.service.DataDictionaryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author 深圳邱道长
 * @since 2019/10/7
 */
@Service
public class DataDictionaryServiceImpl implements DataDictionaryService {


    @Autowired
    private DataDictionaryMapper dataDictionaryMapper;

    @Override
    public List<DataDictionary> findByTypeCode(String cardType) {
        return dataDictionaryMapper.findByTypeCode(cardType);
    }

    @Override
    public ResponseCode query(Integer pageSize,Integer pageNum) {
        PageHelper.startPage(pageNum,pageSize);
        ResponseCode code = new ResponseCode();
        List<DataDictionary> list=dataDictionaryMapper.query();
        PageInfo<DataDictionary> p=new PageInfo<>(list);
        code.setData(list);
        code.setCode(0);
        code.setCount(p.getTotal());
        return code;

    }

    @Override
    public void add(DataDictionary d) {
        dataDictionaryMapper.add(d);
    }

    @Override
    public DataDictionary queryById(Long id) {
        return dataDictionaryMapper.queryById(id);
    }

    @Override
    public void modify(DataDictionary dataDictionary) {
        dataDictionaryMapper.modify(dataDictionary);
    }

    @Override
    public ResponseCode del(Integer id) {
        Integer row = dataDictionaryMapper.del(id);
        ResponseCode code = new ResponseCode();
        if(row>0){
            code.setCode(ResponseCode.SUCCESS);
            code.setMsg("删除成功！！");
        }else{
            code.setCode(ResponseCode.FAIL);
            code.setMsg("删除失败！！");
        }
        return code;
    }
}
